home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch18
/
fig18_08.txt
< prev
next >
Wrap
Text File
|
1998-02-27
|
626b
|
25 lines
1 // Fig. 18.8: fig18_08.cpp
2 // An example of a union
3 #include <iostream.h>
4
5 union Number {
6 int x;
7 float y;
8 };
9
10 int main()
11 {
12 Number value;
13
14 value.x = 100;
15 cout << "Put a value in the integer member\n"
16 << "and print both members.\nint: "
17 << value.x << "\nfloat: " << value.y << "\n\n";
18
19 value.y = 100.0;
20 cout << "Put a value in the floating member\n"
21 << "and print both members.\nint: "
22 << value.x << "\nfloat: " << value.y << endl;
23 return 0;
24 }